/*   1:    */ package tt.dz.web.controller.financial;
/*   2:    */ 
/*   3:    */ import com.alibaba.fastjson.JSON;
/*   4:    */ import java.util.ArrayList;
/*   5:    */ import java.util.HashMap;
/*   6:    */ import java.util.Iterator;
/*   7:    */ import java.util.List;
/*   8:    */ import java.util.Map;
/*   9:    */ import javax.annotation.Resource;
/*  10:    */ import javax.servlet.http.HttpServletRequest;
/*  11:    */ import javax.servlet.http.HttpServletResponse;
/*  12:    */ import org.apache.commons.lang3.StringUtils;
/*  13:    */ import org.apache.commons.lang3.math.NumberUtils;
/*  14:    */ import org.springframework.stereotype.Controller;
/*  15:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  16:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  17:    */ import tt.dz.biz.service.financial.MerchantService;
/*  18:    */ import tt.dz.common.BusinessException;
/*  19:    */ import tt.dz.common.LogUtil;
/*  20:    */ import tt.dz.vo.MerchantVO;
/*  21:    */ import tt.dz.vo.ResponseModle;
/*  22:    */ import tt.dz.web.controller.BaseController;
/*  23:    */ 
/*  24:    */ @Controller
/*  25:    */ public class MerchantController
/*  26:    */   extends BaseController
/*  27:    */ {
/*  28:    */   @Resource(name="merchantService")
/*  29:    */   private MerchantService merchantService;
/*  30:    */   
/*  31:    */   @RequestMapping(value={"/listAllMerchant"}, produces={"application/json;charset=UTF-8"})
/*  32:    */   @ResponseBody
/*  33:    */   public String listAllMerchant()
/*  34:    */   {
/*  35: 39 */     ResponseModle responseModle = null;
/*  36:    */     try
/*  37:    */     {
/*  38: 41 */       List<MerchantVO> merchantList = this.merchantService.listAllMerchant();
/*  39: 42 */       responseModle = new ResponseModle("success", merchantList);
/*  40:    */     }
/*  41:    */     catch (Exception e)
/*  42:    */     {
/*  43: 44 */       LogUtil.error("查询运营商异常", e);
/*  44: 45 */       responseModle = new ResponseModle("error", new ArrayList());
/*  45:    */     }
/*  46: 47 */     return JSON.toJSONString(responseModle);
/*  47:    */   }
/*  48:    */   
/*  49:    */   @RequestMapping(value={"/mapAllVirtualMerchant"}, produces={"application/json;charset=UTF-8"})
/*  50:    */   @ResponseBody
/*  51:    */   public String mapAllVirtualMerchant()
/*  52:    */   {
/*  53: 57 */     ResponseModle responseModle = null;
/*  54:    */     try
/*  55:    */     {
/*  56: 59 */       List<MerchantVO> merchantList = this.merchantService.listAllVirtualMerchant();
/*  57: 60 */       Iterator<MerchantVO> iterator = merchantList.iterator();
/*  58: 61 */       MerchantVO sourceMerchant = null;
/*  59: 62 */       Map<String, Object> resultMap = new HashMap();
/*  60: 63 */       while (iterator.hasNext())
/*  61:    */       {
/*  62: 64 */         sourceMerchant = (MerchantVO)iterator.next();
/*  63: 65 */         resultMap.put(sourceMerchant.getMerchantCode(), sourceMerchant);
/*  64:    */       }
/*  65: 67 */       responseModle = new ResponseModle("success", resultMap);
/*  66:    */     }
/*  67:    */     catch (Exception e)
/*  68:    */     {
/*  69: 69 */       LogUtil.error("查询虚拟运营商异常", e);
/*  70: 70 */       responseModle = new ResponseModle("error", new ArrayList());
/*  71:    */     }
/*  72: 72 */     return JSON.toJSONString(responseModle);
/*  73:    */   }
/*  74:    */   
/*  75:    */   @RequestMapping(value={"/mapAllMerchant"}, produces={"application/json;charset=UTF-8"})
/*  76:    */   @ResponseBody
/*  77:    */   public String mapAllMerchant()
/*  78:    */   {
/*  79: 82 */     ResponseModle responseModle = null;
/*  80:    */     try
/*  81:    */     {
/*  82: 84 */       List<MerchantVO> merchantList = this.merchantService.listAllMerchant();
/*  83: 85 */       Iterator<MerchantVO> iterator = merchantList.iterator();
/*  84: 86 */       MerchantVO sourceMerchant = null;
/*  85: 87 */       Map<String, Object> resultMap = new HashMap();
/*  86: 88 */       while (iterator.hasNext())
/*  87:    */       {
/*  88: 89 */         sourceMerchant = (MerchantVO)iterator.next();
/*  89: 90 */         resultMap.put(sourceMerchant.getMerchantCode(), sourceMerchant);
/*  90:    */       }
/*  91: 92 */       responseModle = new ResponseModle("success", resultMap);
/*  92:    */     }
/*  93:    */     catch (Exception e)
/*  94:    */     {
/*  95: 94 */       LogUtil.error("查询运营商异常", e);
/*  96: 95 */       responseModle = new ResponseModle("error", new ArrayList());
/*  97:    */     }
/*  98: 97 */     return JSON.toJSONString(responseModle);
/*  99:    */   }
/* 100:    */   
/* 101:    */   @RequestMapping(value={"/modifyMerchant"}, produces={"application/json;charset=UTF-8"})
/* 102:    */   @ResponseBody
/* 103:    */   public String modifyMerchant(HttpServletRequest request, HttpServletResponse response)
/* 104:    */   {
/* 105:109 */     boolean excuteFlag = false;
/* 106:110 */     boolean isCodeinValidate = false;
/* 107:111 */     String mes = "";
/* 108:    */     try
/* 109:    */     {
/* 110:113 */       String modifyType = request.getParameter("modifyType");
/* 111:114 */       MerchantVO merchantVO = (MerchantVO)JSON.parseObject(request.getParameter("merchantVO"), MerchantVO.class);
/* 112:115 */       MerchantVO oldSingleMerchant = null;
/* 113:116 */       if (0 == merchantVO.getProviderType().intValue())
/* 114:    */       {
/* 115:117 */         String signalCode = merchantVO.getSignalCode();
/* 116:118 */         if ((StringUtils.isEmpty(signalCode)) || 
/* 117:119 */           (signalCode.length() != 3) || 
/* 118:120 */           (!NumberUtils.isDigits(signalCode)))
/* 119:    */         {
/* 120:121 */           isCodeinValidate = false;
/* 121:    */         }
/* 122:    */         else
/* 123:    */         {
/* 124:123 */           isCodeinValidate = true;
/* 125:124 */           oldSingleMerchant = this.merchantService.getMerchantSignalCode(merchantVO.getSignalCode());
/* 126:    */         }
/* 127:    */       }
/* 128:    */       else
/* 129:    */       {
/* 130:127 */         merchantVO.setSignalCode("");
/* 131:128 */         isCodeinValidate = true;
/* 132:    */       }
/* 133:130 */       if (!isCodeinValidate)
/* 134:    */       {
/* 135:131 */         mes = "当前运营商代码为空或者格式错误";
/* 136:    */       }
/* 137:134 */       else if ("insert".equals(modifyType))
/* 138:    */       {
/* 139:135 */         if ((0 == merchantVO.getProviderType().intValue()) && (oldSingleMerchant != null)) {
/* 140:136 */           mes = "当前运营商代码已经被使用，不能新增运营商代码";
/* 141:    */         } else {
/* 142:138 */           excuteFlag = this.merchantService.insertMerchant(merchantVO);
/* 143:    */         }
/* 144:    */       }
/* 145:140 */       else if ("update".equals(modifyType))
/* 146:    */       {
/* 147:141 */         boolean isBindCard = false;
/* 148:142 */         if (0 == merchantVO.getProviderType().intValue()) {
/* 149:143 */           if ((oldSingleMerchant != null) && (oldSingleMerchant.getMerchantCode().compareTo(merchantVO.getMerchantCode()) != 0))
/* 150:    */           {
/* 151:144 */             mes = "当前运营商代码已经被使用，不能修改运营商代码";
/* 152:145 */             isCodeinValidate = false;
/* 153:    */           }
/* 154:    */           else
/* 155:    */           {
/* 156:147 */             isBindCard = true;
/* 157:    */             
/* 158:    */ 
/* 159:    */ 
/* 160:151 */             MerchantVO oldMerchant = this.merchantService.queryMerchantByCode(merchantVO.getMerchantCode());
/* 161:152 */             if ((oldMerchant != null) && (oldMerchant.getSignalCode().compareTo(merchantVO.getSignalCode()) != 0))
/* 162:    */             {
/* 163:153 */               isBindCard = this.merchantService.getMerchantCardNoBinded(merchantVO.getMerchantCode()) > 0;
/* 164:154 */               if (isBindCard) {
/* 165:155 */                 mes = "当前运营商存在绑定的卡号，不能修改运营商代码";
/* 166:    */               }
/* 167:    */             }
/* 168:    */             else
/* 169:    */             {
/* 170:158 */               isBindCard = false;
/* 171:    */             }
/* 172:    */           }
/* 173:    */         }
/* 174:162 */         excuteFlag = (isBindCard) || (!isCodeinValidate) ? false : this.merchantService.updateMerchant(merchantVO);
/* 175:    */       }
/* 176:    */     }
/* 177:    */     catch (Exception e)
/* 178:    */     {
/* 179:167 */       LogUtil.error("更改运营商异常", e);
/* 180:    */     }
/* 181:169 */     return JSON.toJSONString(assemblyResponseData(excuteFlag, mes));
/* 182:    */   }
/* 183:    */   
/* 184:    */   @RequestMapping(value={"/queryMerchantSignalCode"}, produces={"application/json;charset=UTF-8"})
/* 185:    */   @ResponseBody
/* 186:    */   public String queryMerchantSignalCode(HttpServletRequest request, HttpServletResponse response)
/* 187:    */   {
/* 188:186 */     boolean excuteFlag = false;
/* 189:187 */     Object result = "";
/* 190:188 */     String signalCode = request.getParameter("signalCode");
/* 191:189 */     if (StringUtils.isEmpty(signalCode)) {
/* 192:190 */       result = "运营商代码为空";
/* 193:    */     } else {
/* 194:    */       try
/* 195:    */       {
/* 196:193 */         result = this.merchantService.getMerchantSignalCode(signalCode);
/* 197:194 */         excuteFlag = true;
/* 198:    */       }
/* 199:    */       catch (BusinessException e)
/* 200:    */       {
/* 201:196 */         result = e.getStatusDescribe();
/* 202:    */       }
/* 203:    */       catch (Exception e)
/* 204:    */       {
/* 205:198 */         result = e.getLocalizedMessage();
/* 206:199 */         LogUtil.error("查询运营商代码异常", e);
/* 207:    */       }
/* 208:    */     }
/* 209:203 */     return JSON.toJSONString(assemblyResponseData(excuteFlag, result));
/* 210:    */   }
/* 211:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.web.controller.financial.MerchantController
 * JD-Core Version:    0.7.0.1
 */